package com.xunshangwang.pinhaohuo.ui.activities;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.xunshangwang.pinhaohuo.R;
import com.xunshangwang.pinhaohuo.ui.fragments.MyGoodsFragment;
import com.xunshangwang.pinhaohuo.ui.fragments.MyShopFragment;

/**
 * Created by xzp on 16/1/25.
 */
public class MyCollectionActivity extends BaseActivity{
    private TabLayout mTabLayout;
    private ViewPager mViewPager;
    private CollectionAdapter mAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_collection);
        mTabLayout= (TabLayout) this.findViewById(R.id.collection_tab_layout);
        mViewPager= (ViewPager) this.findViewById(R.id.collection_view_pager);
        mAdapter=new CollectionAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(mAdapter);
        mTabLayout.setupWithViewPager(mViewPager);
    }
    private class CollectionAdapter extends FragmentPagerAdapter{
        private String[] mPageTitles;
        public CollectionAdapter(FragmentManager fm) {
            super(fm);
            mPageTitles=getResources().getStringArray(R.array.collection_page_title_array);
        }

        @Override
        public Fragment getItem(int position) {
            if(position==0){
                return new MyGoodsFragment();
            }
            else {
                return new MyShopFragment();
            }
        }

        @Override
        public int getCount() {
            return 2;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mPageTitles[position];
        }
    }
}
